# import sqlite3
# import os

# filename = 'ktr_usb.db'
# file_dir = "/home/marvsmart/factory/data/"

# file_path = os.path.join(file_dir, filename)
# conn = sqlite3.connect(file_path)

# c = conn.cursor()

# en = c.execute("SELECT EN, data1, data2 from Robot_state where ID=1")
# data_en = en.fetchall()
# print(data_en)
# print("数据库操作成功")
# conn.close()


import sqlite3
import os

filename = 'ktr_usb.db'
file_dir = "/home/marvsmart/factory/data/"
file_path = os.path.join(file_dir, filename)

# 连接到SQLite数据库
conn = sqlite3.connect(file_path)
c = conn.cursor()

# 创建一个新的临时表，并把数据复制过去
c.execute("CREATE TABLE Robot_state3 AS SELECT * FROM Robot_state WHERE 1=1")

# 删除原来的表
c.execute("DROP TABLE Robot_state")

# 此处实际上已经完成了重命名，因为我们删除了旧表并保留了新表名为最终所需名字

# 提交事务
conn.commit()

print("数据库操作成功")
conn.close()